package staticinner;

import staticinner.StaticInnerSingleton;

import java.io.*;

public class SerializeSingletonTest {

    public static void main(String[] args) throws Exception {

        StaticInnerSingleton s1 = null;
        StaticInnerSingleton s2 = StaticInnerSingleton.getInstance();
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("StaticInnerSingleton.obj");
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(s2);
            oos.flush();
            oos.close();
            FileInputStream fis = new FileInputStream("StaticInnerSingleton.obj");
            ObjectInputStream ois = new ObjectInputStream(fis);
            s1 = (StaticInnerSingleton)ois.readObject();
            ois.close();
            System.out.println(s1);
            System.out.println(s2);
            System.out.println(s1 == s2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
